#!/usr/bin/python
# -- coding:utf8 --

import app.model_phl.util_log as utils
from app.model_phl.utils import select_sql_mysql_v1
import warnings

warnings.filterwarnings('ignore')


def get_age_data(ApplyNO):
    """
    从MySQL获取年龄数据
    :param ApplyNO:
    :return:
    """
    age_sql = f"""
    select distinct 
    UserId
    ,if(Birthday is null, -9999, TIMESTAMPDIFF(YEAR, Birthday, CURDATE())) as age 
    from SysCardAuthentication
    where UserId = (
    select distinct 
    UserId
    from SysJkApply
    where ApplyNO = '{ApplyNO}' 
    )
    """
    age_data = select_sql_mysql_v1(age_sql)
    return age_data


def get_userinfo_freatures(ApplyNO):
    """
    用户基本信息数据的特征集
    :param ApplyNO:
    :return:
    """
    try:
        user_df = get_age_data(ApplyNO)
        if user_df.empty:
            return {
                'age': -9999
            }
        age = user_df.loc[0, 'age']

        return {
            'age': age,
        }
    except Exception as e:
        utils.get_logger().error(e)
        return {
            'age': -9976,
        }


if __name__ == '__main__':
    # ApplyNO = '169699371854543670'
    ApplyNO = '169736809782272554'
    print(get_userinfo_freatures(ApplyNO))
